﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreFrame.Business;
using MarchEstate.Manager.BusinesEntity;
using CoreFrame.Core.Orm;

namespace MarchEstate.Manager.Dao.Init
{
    public class ServiceItemDao : AbstractDao
    {
        public System.Data.DataTable GetStatItemData()
        {
            string strsql = @"select * from WY_StatItem";
            return oleDb.GetDataTable(strsql);
        }

        public AbstractServiceItem GetServiceItem(string _code)
        {
            return BindEntity<AbstractServiceItem>.CreateInstanceDAL(oleDb, WorkId).GetModel((object)_code);
        }

        public List<AbstractServiceItem> GetServiceItemList(string _statCode, string _type)
        {
            string strWhere = "";
            if (_statCode != "")
                strWhere = "StatCode in (" + _statCode + ")";
            if (_type != "")
            {
                if (strWhere != "")
                    strWhere += " and ItemType in (" + _type + ")";
                else
                    strWhere += " ItemType in (" + _type + ")";
            }
            return BindEntity<AbstractServiceItem>.CreateInstanceDAL(oleDb, WorkId).GetListArray(strWhere);
        }

        public bool AddStatItem(string code, string statname)
        {
            string strsql = @"insert into wy_statitem values('{0}','{1}')";
            strsql = String.Format(strsql, code, statname);
            return oleDb.DoCommand(strsql) > 0;
        }

        public bool UpdateStatItem(string code, string statname)
        {
            string strsql = @"update wy_statitem set statname='{0}' where code='{1}'";
            strsql = String.Format(strsql, statname, code);
            return oleDb.DoCommand(strsql) > 0;
        }

        public bool ExistStatitemcode(string code)
        {
            string strsql = @"select count(1) from wy_statitem where code ='{0}'";
            strsql = String.Format(strsql, code);
            return Convert.ToInt32(oleDb.GetDataResult(strsql)) > 0;
        }

        public bool DeleteStatItem(string code)
        {
            string strsql = @"delete from wy_statitem where code='{0}'";
            strsql = String.Format(strsql, code);
            return oleDb.DoCommand(strsql) > 0;
        }

        public bool Existserviceitemcode(string code)
        {
            string strsql = @"select count(1) from wy_serviceitem where code ='{0}'";
            strsql = String.Format(strsql, code);
            return Convert.ToInt32(oleDb.GetDataResult(strsql)) > 0;
        }

        public bool AddServiceItem(AbstractServiceItem item)
        {
            return BindEntity<AbstractServiceItem>.CreateInstanceDAL(oleDb, WorkId).Add(item) > 0;
        }

        public bool UpdateServiceItem(AbstractServiceItem item)
        {
            return BindEntity<AbstractServiceItem>.CreateInstanceDAL(oleDb, WorkId).Update(item) > 0;
        }
    }
}
